<?php

namespace app\admin\validate;

use think\Validate;

class Power extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名'	=>	['规则1','规则2'...]
     *
     * @var array
     */
    protected $rule = [];

    /**
     * 定义错误信息
     * 格式：'字段名.规则名'	=>	'错误信息'
     *
     * @var array
     */
    protected $message = [];
    //场景
    protected $scene = [];

    public function __construct()
    {
        $this->batch();
        $this->rule=[
            'menu_id'               => 'require|integer',
            'menu_pid'              => 'require|integer',
            'menu_name'             => ['require','regex'=>'/^[A-Z_a-z][A-Z_0-9\/a-z]*/'],
            'menu_title'            => 'require',
            'menu_icon'             => 'require',
            'menu_status'           => 'require|integer',
            'menu_order'            => 'require|integer',
            'menu_show'             => 'require|integer',

            'group_title'           => 'require',
            'group_status'          => 'require|integer',
            'group_rules'           => 'require',

            'member_user'           =>'require',
            'member_head'           =>'require',
            'member_sex'            =>'require|integer',
            'member_qq'             =>['regex'=>'/^[1-9][0-9]{4,9}$/'],
            'member_phone'          =>'mobile',
            'member_email'          =>'email',
            'member_birthday'       =>['regex'=>'/^\d{4}-\d{2}-\d{2}$|^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/'],
        ];
        $this->message=[
            'member_qq.regex'       =>lang('member_qq').lang('need_qq'),
            'member_user.require'   =>'管理员名称'.lang('require'),
            'member_sex.require'    =>lang('member_sex').lang('require'),
            'member_sex.integer'    =>lang('member_sex').lang('need_int'),
            'member_phone.mobile'   =>lang('member_phone').lang('need_mobile'),
            'member_email.email'    =>lang('member_email').lang('need_email'),
            'is_admin.require'      =>lang('is_admin').lang('require'),
            'is_admin.integer'      =>lang('is_admin').lang('need_int'),
        ];
        $this->scene=[
            'menu_save'         =>['menu_pid','menu_name','menu_title','menu_status','menu_order','menu_show'],
            'group_save'         =>['group_title','group_status'],
            'admin_save'         =>['member_user','member_sex','member_phone','member_email','is_admin','member_qq'],
        ];
    }
    public function group_save($p=''){
        $this->message['group_title.require'] = lang('group_title').lang('require');
        $this->message['group_status.require'] = lang('group_status').lang('require');
        $this->message['group_status.integer'] = lang('group_status').lang('need_int');
        return $this->scene('group_save')->check($p);
    }

    public function admin_save($p=''){
        return $this->scene('admin_save')->check($p);
    }
}